/** @odoo-module **/

import {registry} from "@web/core/registry";
import { _t } from "@web/core/l10n/translation";
import {browser} from "@web/core/browser/browser";


function preferencesItem(env) {
    return {
        type: "item",
        id: "settings",
        description: _t("Preferences"),
        callback: async function () {
            const actionDescription = await env.services.orm.call("res.users", "action_get");
            actionDescription.res_id = env.services.user.userId;
            env.services.action.doAction(actionDescription);
        },
        sequence: 50,
        hide: false,
        icon: "fa fa-cog",
    };
}

function logOutItem(env) {
    const route = "/web/session/logout";
    return {
        type: "item",
        id: "logout",
        description: _t("Log out"),
        href: `${browser.location.origin}${route}`,
        callback: () => {
            browser.location.href = route;
        },
        sequence: 140,
        hide: false,
        icon: "fa fa-power-off",
    };
}

registry.category("user_menuitems").add("profile", preferencesItem);
registry.category("user_menuitems").add("log_out", logOutItem);